<?php

namespace App\Repositories;

use App\User\Favors;
use App\User\Question;

class UserQuestionRepositories
{
    public function subject($subject)
    {
        $subject = \DB::table('subjects')->find($subject);
        return $subject;
    }

    public function sections($subject)
    {
        $sections = \DB::table('sections')->where('subject', $subject)->orderBy('order', 'asc')->get();
        return $sections;
    }

    public function question($request)
    {
        $section = $request->section;
        $type = $request->type;
        $question = !$type ? Question::where('sections', $section)->paginate(10) :
            Question::where('sections', $section)->where('type', $type)->paginate(10);
        //数字10代表每页显示10条数据
        return $question;
    }

    public function errors($userid)
    {
        $errors=Favors::where('userid',$userid)->count();
        return $errors;
    }

}
